fn main() {
    let mut x = 4;
    println!("The value is {}", &x);
    x = 6;
    println!("The value is {}", &x);

    // shadow
    let y = 5;
    let y = y * 2;
    println!("shadow value : {}", y);

    // shadow - 类型可以与之前不同
    let z = "    ";
    let z = z.len();
    println!("{}", z);

    // 类型 - 对使用的值，编译器能够知道他的类型；但是如果可能得类型比较多，需要标注类型
    let guess: u32 = "45"
        .parse()
        .expect("Type is error, expect a string an to i32");
    println!("guess: {}", guess);

    // // 浮点类型
    // let m = 2.0; // f64
    // let n: f32 = 3.0; // f32

    // // 数值运算
    // let s1 = 5 + 10; // i32
    // let s2 = 10.5 - 5.5; // f64
    // let s3 = 5 * 10; // i32
    // let s4 = 90.5 / 32.2; // f64
    // let s5 = 54 % 5; // i32

    // // 字符类型
    // let o1 = 'z';
    // let o2: char = 'ぃ';

    // Tuple 元组
    let t: (i32, f64, char) = (10, 34.2, 'z');
    let (t1, t2, t3) = t;
    println!("{}, {}, {}", t.0, t.1, t.2);
    println!("{}, {}, {}", t1, t2, t3);

    another_fn(-1, 10)
}

fn another_fn(x: i32, y: u32) {
    println!("The value of x is: {}", x);
    println!("The value of y is: {}", y);
    println!("plus_five value of: {}", plus_five(6));

    let condition = true;

    let z = if condition { 5 } else { 6 };
    println!("if 表达式返回值: {}", z);

    let mut count = 0;
    let result = loop {
        count += 1;
        if count == 10 {
            break count * 2;
        }
    };
    println!("loop 表达式返回值：{}", result);

    let mut number = 3;

    while number != 0 {
        println!("number: {}", number);
        number -= 1;
    }

    let a = [10, 20, 30, 40, 50];
    for element in a.iter() {
        println!("element: {}", element);
    }

    for item in (1..4).rev() {
        println!("number: {}", item)
    }
}

fn plus_five(x: i32) -> i32 {
    if x < 5 {
        println!("small")
    } else {
        println!("big")
    }
    x + 5 // 最后的表达式作为返回值 x + 5 ，如果加了封号，则变为一个语句了，返回类型就变为空tuple () 了
}
